import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { UserModule } from './user/user.module';
import { userInfo } from 'os';
import { PersonModule } from './person/person.module';

@Module({
  imports: [UserModule, PersonModule],
  // 只能被注入到IOC容器
  controllers: [AppController],
  // 既能被注入到IOC容器，又能被注入别的对象中
  providers: [
    AppService,
    {
      provide: 'userInfo',
      useValue: {
        name: 'ljj',
        age: 20,
      },
    },
    {
      provide: 'userInfo2',
      useExisting: 'us2',
      useFactory(userInfo: { age: number }, appService: AppService) {
        return {
          age: userInfo.age,
          desc: appService.getHello(),
        };
      },
      inject: ['userInfo', AppService],
    },
  ],
})
export class AppModule {}
